var listionhajax = '';
var is_ajax_list = '';
var page = 2;

function update_user() {

    var bankno = $('.bankno').val();
    var province = $('.province').val();
    var city = $('.city').val();
    var address = $('.address').val();
    var accntnm = $('.accntnm').val();
    var accntno = $('.accntno').val();
    var scard = $('.scard').val();
    var phone = $('.phone').val();
    var id = $('.id').val();


    if(!bankno){layer.msg('请选择银行');return false;}
    if(!province){layer.msg('请选择省份');return false;}
    if(!city){layer.msg('请选择城市');return false;}
    if(!address){layer.msg('请输入支行地址');return false;}
    if(!accntnm){layer.msg('请输入开户名称');return false;}
    if(!accntno){layer.msg('请输入卡号');return false;}
    if(!scard){layer.msg('请输入身份证号码');return false;}
    if(!phone){layer.msg('请输入手机号');return false;}


    var postdata = 'bankno='+bankno+"&provinceid="+province+"&cityno="+city+"&address="+address+"&accntnm="+accntnm+"&accntno="+accntno+"&scard="+scard+"&phone="+phone;
    if(id){
        postdata += "&id="+id
    }
    var posturl = "/index/user/dobanks";
    $.post(posturl,postdata,function(resdata){
        layer.msg(resdata.data);

        if(resdata.type == 1){
            setTimeout('gourl()',1000);
        }

    })


}



function gourl() {

    history.go(-1);

}

function out_withdraw() {

    var t_url = $('.modal-bank .t_url').val();
    var t_num=$('.modal-bank .price').val();
    var t_num2=$('.modal-bank .t_num').val();
    var postdata = 't_url=' + t_url+"&price="+t_num+"&t_num="+t_num2;
    var posturl = '/index/user/cash';
    $.post(posturl, postdata, function (resdata) {

        layer.msg(resdata.data);
        if (resdata.type == 1) {
            setTimeout('gourl()', 1000);
        }

    })


}

/**
 * 出金申请
 * @author lukui  2017-07-04
 * @return {[type]} [description]
 */
/*
function out_withdraw() {

   var price = $('.cash-price').val();
   var cash_min = $('.cash_min').html();
   var cash_max = $('.cash_min').attr('attrmax');
   if(price*10 < cash_min*10){
       layer.msg('最低提现金额为'+cash_min);
       return false;
   }

   if(price*10 > cash_max*10){
       layer.msg('最高提现金额为'+cash_max);
       return false;
   }

   var postdata = 'price='+price;
   var posturl = '/index/user/cash';
   $.post(posturl,postdata,function(resdata){

       layer.msg(resdata.data);
       if(resdata.type == 1){
           setTimeout('gourl()',1000);
       }

   })






}
*/
/**
 * 充值
 * @author lukui  2017-07-04
 * @return {[type]} [description]
 */
function re_withdraw() {

    var t_num=$(' .modal-re .t_num').val();
    var price=$(' .modal-re .t_oney').val();
    var postdata = "t_num="+t_num+"&price="+price;
    var posturl = '/index/user/userre';
    $.post(posturl, postdata, function (resdata) {

        layer.msg(resdata.data);
        if (resdata.type == 1) {
            //setTimeout('gourl()', 1000);
            window.location.href="/index/user/index";
        }

    })


}

/**
 * 监听输入提现金额
 * @author lukui  2017-07-05
 * @param  {[type]} ) {		var       price [description]
 * @return {[type]}   [description]
 */
$('.cash input').bind('input propertychange', function() {
    var price = $('.cash-price').val();
    var reg_par = $('.reg_par').attr('attrdata');
    var true_price = (price*(100-reg_par)/100).toFixed(2);
    $('.true_price').html(true_price);
    $('.true_price').show();

});


/**
 * 资金流水
 * @author lukui  2017-07-05
 * @param  {[type]} ){	var isshow        [description]
 * @return {[type]}         [description]
 */
$(document).on("click",'.price_list li',function(){

    var isshow = $(this).attr('isshow');
    if(isshow == 0){

        $('.today_list_footer').hide();
        $('.price_list li').attr('isshow',0);
        $('.clickshow').addClass('ion-ios-arrow-up');
        $('.clickshow').removeClass('ion-ios-arrow-down');


        $(this).find('.clickshow').removeClass('ion-ios-arrow-up');
        $(this).find('.clickshow').addClass('ion-ios-arrow-down');

        $(this).find('.today_list_footer').show();
        $(this).attr('isshow',1);

    }else{

        $(this).find('.clickshow').addClass('ion-ios-arrow-up');
        $(this).find('.clickshow').removeClass('ion-ios-arrow-down');

        $(this).find('.today_list_footer').hide();
        $(this).attr('isshow',0);

    }


});



listionhajax = setInterval("listionh()",1000);
/**
 * 监听高度
 * @author lukui  2017-07-05
 * @return {[type]} [description]
 */
function listionh() {
    if($(".price_list li:last").attr('ng-repeat')){
        var ScrollTop = $(".price_list li:last").offset().top;

        if(ScrollTop <1000 ){
            ajax_price_list();
        }
    }

}

/**
 * ajax加载资金流水
 * @author lukui  2017-07-05
 * @return {[type]} [description]
 */
function ajax_price_list() {


    var url = "/index/user/ajax_price_list?page="+page;
    var html = '';
    if(is_ajax_list == 1){
        return ;
    }
    is_ajax_list = 1;


    $.get(url,function(resdata){

        console.log(resdata);


        var res_list = resdata.data;
        if(res_list.length == 0){
            clearInterval(listionhajax);
            is_ajax_list = 1;
            return;
        }
        $.each(res_list,function(k,v){
            if(v.type == 2){
                var other_money = v.account*-1;
            }else{
                var other_money = v.account;
            }
            html += '<li ng-repeat="c in moneyList" class="" isshow="0">\
                	<div class="money_list_header">\
                		<section class="other_money_bg">\
                		</section><section>\
                			<p class="ng-binding other_money">'+v.title+'</p>\
                			<p>\
                				<i class="iconfont icon--1 "></i>\
                				<i class="iconfont icon-30 ng-hide"></i>\
                				<span class="ng-binding">'+v.nowmoney+'</span></p>\
                			<p>\
                				<i class="iconfont icon--2 pay_blue"></i>\
                				<span class="ng-binding">'+getLocalTime(v.time)+'</span>\
                			</p>\
                		</section><section class="ng-binding other_money">\
                			'+other_money+'                		</section><section class="icon clickshow ion-ios-arrow-up">\
                		</section>\
                	</div>\
                	<article class="today_list_footer" style="display: none;">\
                		<p class="ng-binding">详情：'+v.content+'</p>\
                	</article>\
                </li>';



        })
        $('.price_list').append(html);
        page++;
        is_ajax_list = 0;

    })




}

/**
 * 发送邮箱验证码
 * @return {[type]} [description]
 */
function get_smg() {


    var email = $('.email').val();

    if(!(/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z.]{2,8})$/.test(email))){
        var reg_16 = $("#reg_16").val();
        layer.msg(reg_16);
        return false;
    }


    var url = "/index/login/sendmsg/email/"+email;
    $.get(url,function(resdata){
        layer.msg(resdata.data);
        if(resdata.code == 1){
            $(".code_btn").attr('onclick',"return false;");
            listion_sendmsg();
        }
    })
    return false;
}

/**
 * 发送验证码
 * @return {[type]} [description]
 */
function get_svg() {


    var phone = $('.username').val();
    var language = $("#language").val();
    var code = '86';
    if(language == 'zh-cn'){
        if(!(/^1[34578]\d{9}$/.test(phone))){
            var reg_18 = $("#reg_18").val();
            layer.msg(reg_18);
            return false;
        }
    }else{
        code = $("#countryCode").val();
    }



    var url = "/index/login/sendmsm/phone/"+phone+"/code/"+code;
    $.get(url,function(resdata){
        console.log(resdata);
        layer.msg(resdata.data);
        if(resdata.type == 1){
            $(".code_btn").attr('onclick',"return false;");
            listion_sendmsm();
        }
    })
    return false;
}

function listion_sendmsm(){

    var time= 61;
    setTime=setInterval(function(){
        if(time<=1){
            clearInterval(setTime);
            $(".code_btn").text("再发一次");
            $(".code_btn").attr('onclick',"return get_svg();");
            return;
        }
        time--;
        $(".code_btn").text(time+"s");

    },1000);
}

function listion_sendmsg(){

    var time= 61;
    setTime=setInterval(function(){
        if(time<=1){
            clearInterval(setTime);
            var reg_17 = $("#reg_17").val();
            $(".code_btn").text(reg_17);
            $(".code_btn").attr('onclick',"return get_smg();");
            return;
        }
        time--;
        $(".code_btn").text(time+"s");

    },1000);
}

function submit_deposit2() {

    can_balance(0)

    if(pay_type == ''){
        layer.msg('请选择支付类型');
        can_balance(1)
        return false;
    }

    document.form1.submit();
    return true;
}
/**
 * 充值
 * @return {[type]} [description]
 */
function submit_deposit() {

    can_balance(0)
    var user_17 = $("#user_17").val();
    var user_18 = $("#user_18").val();
    if(pay_type == ''){
        layer.msg(user_17);
        can_balance(1)
        return false;
    }

    var bpprice = $('.bpprice').val();

    if(!bpprice || isNaN(bpprice)){
        layer.msg(user_18);
        can_balance(1)
        return false;
    }

    document.form1.submit();
    return true;

}

function check_payid(id) {
    pay_type = id;
    if(pay_type == 'codepay_wx'){
        $("#pay_type").val(5);
        $(".reg_cz").show();
        $(".reg_list").show();
        $(".reg_btn").show();
        $(".reg_btn2").hide();
        $("#form1").attr('action','/codepay/diypay.php');
    }else if(pay_type == 'codepay_ali'){
        $("#pay_type").val(2);
    }else if(pay_type == 'codepay_alipay'){
        $("#pay_type").val(3);
    }else if(pay_type == 'codepay_xia'){
        $(".reg_cz").hide();
        $(".reg_list").hide();
        $(".reg_btn").hide();
        $(".reg_btn2").show();
        $("#form1").attr('action','/index/user/pay5');
    }
}


//调用微信JS api 支付
function jsApiCall(obj)
{

    WeixinJSBridge.invoke(
        'getBrandWCPayRequest',
        obj,
        function(res){
            WeixinJSBridge.log(res.err_msg);
            //alert(res.err_code+'|'+res.err_desc+'|'+res.err_msg);
            if(res.err_msg.indexOf('ok')>0){
                layer.msg('充值成功！');
                window.location.href=returnrul;
            }
        }
    );
}

function callpay(obj)
{
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', jsApiCall);
            document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
        }
    }else{
        jsApiCall(obj);
    }
}


function sQrcode(qdata,classname){
    console.log(qdata);
    $("."+classname).empty().qrcode({		// 调用qQcode生成二维码
        render : "canvas",    			// 设置渲染方式，有table和canvas，使用canvas方式渲染性能相对来说比较好
        text : qdata,    				// 扫描了二维码后的内容显示,在这里也可以直接填一个网址或支付链接
        width : "165",              	// 二维码的宽度
        height : "165",             	// 二维码的高度
        background : "#ffffff",     	// 二维码的后景色
        foreground : "#000000",     	// 二维码的前景色
        src: ""    						// 二维码中间的图片
    });

}


/**
 * 扫码支付区域
 * @return {[type]} [description]
 */
function pay_code_area(type) {
    if(type == 0){
        $('.pay_code_area').hide();
    }else if(type == 1){
        $('.pay_code_area').show();
        can_balance(1);
    }
}


function can_balance(type) {
    if(type == 0){
        $('.reg_btn').attr('onclick',' ');
        //$('.reg_btn').html('请稍后');
    }else if(type == 1){
        $('.reg_btn').attr('onclick','submit_deposit()');
        //$('.reg_btn').html('确认充值');
    }
}

//充值配置
function reg_push(num) {
    if(!num){
        return false;
    }
    $('.bpprice').val(num);
    $("#price").val(num);
    $(".cny").html(num * 7);
}

//充值配置
function reg_coin(coin,obj) {
    $("#coin_type").val(coin);
    $(obj).css('background','red').siblings().css('background','#081724');
}